<?php
	/** PAGE NOT ALLOWED
	 * Verify if user called this page through a allowed page.
	 * @message: That file cannot be displayed alone.
	 */
	 // $allowed_page=true;
	  
	if (!isset($allowed_page)) { echo "That file cannot be displayed alone."; exit; }
	require_once("d5power.DAO.php");
	//Dotk Equipment class.
	class Equipment extends DAO {

	 private $Equipment_id;
	 private $name;
	 private $weight;
	 private $defense;
	 private $attack;
	 private $image;
	 private $type_id; 
 
	 //Getters and Setters
	public function getEquipment_id() {
		return $this->Equipment_id;
	}
	
	public function setEquipment_id($Equipment_id) {
		$this->Equipment_id = $Equipment_id;
	}
	
	public function getName() {
		return $this->name;
	}
	
	public function setName($name) {
		$this->name = $name;
	}
	
	public function getWeight() {
		return $this->weight;
	}
	
	public function setWeight($weight) {
		$this->weight = $weight;
	}
	
	public function getDefense() {
		return $this->defense;
	}
	
	public function setDefense($defense) {
		$this->defense = $defense;
	}
	
	public function getAttack() {
		return $this->attack;
	}
	
	public function setAttack($attack) {
		$this->attack = $attack;
	}
	
	public function getImage() {
		return $this->image;
	}
	
	public function setImage($image) {
		$this->image = $image;
	}
	
	public function getType_id() {
		return $this->type_id;
	}
	
	public function setType_id($type_id) {
		$this->type_id = $type_id;
	}
	
	 public function load($itemId) {
		$sql = "select
				  type_id, name, weight, defense, attack, image
				from
				  EQUIPMENT
				where
				  equipment_id = ?";
		$result = $this->retrieve($sql, array($itemId))->getRow();
		
		$this->equipment_id= $result['equipment_id'];
        $this->type_id = $result['type_id'];
		$this->name = $result['name'];
		$this->weight = $result['weight'];
		$this->defense = $result['defense'];
		$this->attack = $result['attack'];
		$this->image = $result['image'];	
				
		
		return $this;	
      }
	  
	function create($type_id, $name, $weight, $defense, $attack, $image) {
		$sql = "INSERT INTO EQUIPMENT (type_id, name, weight, defense, attack, image) VALUES(?,?,?,?,?,?)";
		try {
		  $this->retrieve($sql, array($type_id, $name, $weight, $defense, $attack, $image));
		  return true;
		}
		catch(Exception $e) {
		  return false;
		}
	 }
	 
	 
	 public function save() {
		$sql = "UPDATE EQUIPMENT SET type_id= ?,name= ?,weight= ?,defense= ?,attack= ?,image= ? WHERE equipment_id = ? ";
		$playerResult = $this->retrieve($sql, array($this->type_id,$this->name,$this->weight,$this->defense,$this->attack,$this->image,$this->Equipment_id));
	 }
	
	public function delete() {
    	$sql = "DELETE from EQUIPMENT WHERE equipment_id = ? ";
    	$playerResult = $this->retrieve($sql,array($this->Equipment_id));
  	}


 
}
 // $c = new Equipment();
 // $c->setEquipment_id(2);
 // print($c->create(1,"Espad�o",1,12,12,"espada.gif"));
  //print($c->delete());

 
?>